import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo1 {
    public static void main(String[] args) throws SQLException {
        //创建一个DataSource 找到数据库位置
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/test_11_27?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("731889*a");

        //建立和数据库服务器之间的连接
        Connection connection = dataSource.getConnection();

        //构造sql
        String sql = "insert into student values(7,'赵子锐')";
        PreparedStatement statement = connection.prepareStatement(sql);

        //4.把sql发给服务器
        int n = statement.executeUpdate();
        System.out.println(("n = " + n));

        //5.关闭连接 释放资源
        statement.close();
        connection.close();

    }
}
